package com.asen.commons.core.jdbc.config;

import com.asen.commons.core.jdbc.Jdbc;
import com.asen.commons.core.jdbc.impl.JdbcImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * BaseDao配置
 *
 * @author Gary
 * @version 1.0
 * @date 2022-01-02
 */
@Configuration
@ConditionalOnClass({JdbcTemplate.class})
public class BaseDaoAutoConfiguration {

    @Bean
    @Primary
    @ConditionalOnMissingBean(Jdbc.class)
    public Jdbc baseJdbc(DataSource dataSource) {
        Jdbc jdbc = new JdbcImpl();
        jdbc.setDataSource(dataSource);
        return jdbc;
    }
}
